using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TankWars.Weapons
{
    /// <summary>
    /// Base class for all shots
    /// </summary>
    abstract public class Shot : MovableSprite
    {
        public Tank FiringTank;

        protected int nPower;
        protected double dTimeBetweenFiring;

        protected string strExplodeAnimationLabel = "Default";

        /// <summary>
        /// Amount of damage each shot does
        /// </summary>
        public int Power
        {
            get
            {
                return this.nPower;
            }
        }

        public string ExplodeAnimationLabel
        {
            get
            {
                return this.strExplodeAnimationLabel;
            }
        }

        public bool bIsExploded = false;

        public Shot(Texture2D spriteTexture)
            : base(spriteTexture)
        {
        }

        public Shot(string strSpriteName, Texture2D spriteTexture, string strFrameXMLFile)
            : base(strSpriteName, spriteTexture, strFrameXMLFile)
        {
        }

        /// <summary>
        /// Returns the line of a bullet.
        /// </summary>
        /// <returns></returns>
        new public Vector2[] getPoints()
        {
            Vector2[] point = new Vector2[2];

            //Get top left point.
            float x = (-1) * this.SpriteWidth / 2;
            float y = (-1) * this.SpriteHeight / 2;
            float r = (float)Math.Sqrt(x * x + y * y);
            float cosine = (float)(Math.Cos((fRotation + Math.Atan(y / x))));
            float sine = (float)(Math.Sin((fRotation + Math.Atan(y / x))));
            point[0].X = (-1) * r * cosine + vPosition.X;
            point[0].Y = (-1) * r * sine + vPosition.Y;

            //Get bottom right point
            x = this.SpriteHeight / 2;
            y = this.SpriteHeight / 2;
            r = (float)Math.Sqrt(x * x + y * y);
            cosine = (float)(Math.Cos((fRotation + Math.Atan(y / x))));
            sine = (float)(Math.Sin((fRotation + Math.Atan(y / x))));
            point[1].X = r * cosine + vPosition.X;
            point[1].Y = r * sine + vPosition.Y;

            return point;
        }

        public Vector2[] getLine()
        {
            Vector2[] point = new Vector2[2];

            //Get left point.
            float r = this.SpriteWidth / 2;
            float cosine = (float)(Math.Cos(fRotation));
            float sine = (float)(Math.Sin(fRotation));
            point[0].X = (-1) * (r * cosine+3) + vPosition.X;
            point[0].Y = (-1) * (r * sine+3) + vPosition.Y;

            //Get right point
            point[1].X = r * cosine + vPosition.X;
            point[1].Y = r * sine + vPosition.Y;

            return point;
        }


    }
}